package cn.itcast.myprofile.service.impl;

import cn.itcast.myprofile.bean.dto.TagDto;
import cn.itcast.myprofile.bean.po.TagPo;
import cn.itcast.myprofile.repo.TagRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
@Service
public class TagServiceImpl implements TagService {
    @Autowired
    private TagRepo tagRepo;
    @Override
    public List<TagDto> findTagsByPid(Long pid) {
        List<TagPo>list=tagRepo.findByPid(pid);
        List<TagDto> result = list.stream().map(this::convert).collect(Collectors.toList());
        return result;
    }
    /**
     * 将标签的po对象转换为dto对象
     * @param po
     * @return
     */
    private TagDto convert(TagPo po) {
        return new TagDto(po.getId(), po.getName(), po.getRule(), po.getLevel(), po.getPid(), po.getState());
    }
}
